<template>
	<div class="theme">
		<van-nav-bar :title="$t('MySettlementRecord.v1')" :left-text="$t('MyDividend.v6')" left-arrow @click-left="onClickLeft" />
		<div class="overlay headTop">
			<div class="overlay-content scrolling" style="padding-top:10px;">
				<van-pull-refresh v-model="isLoading" @refresh="onRefresh" pulling-text=" " :loosing-text="$t('MyDividend.v7')" :loading-text="$t('MyDividend.v8')">
					<van-list v-model="loading" :finished="finished" :finished-text="$t('MyDividend.v9')" :loading-text="$t('MyDividend.v8')" @load="onLoad">
						<div style="background: white;border-bottom: 1px solid #ebedf0;" v-for="(item,index) in list" :key="item.index" class="bg-overlayColor product-title-border-color product-title-color">
							<div style="padding: 10px;">
								<van-row>
									<van-col span="12">
										<span>
					                      {{$t('MySettlementRecord.v2')}}
					                    </span>
										<div style="padding-top: 5px;font-size: 13px;color: rgb(125, 126, 128);">
											{{item.createTime | formatDate}}
										</div>
									</van-col>
									<van-col span="12" style="text-align: right;">
										<span>
					                      {{$t('MySettlementRecord.v3')}}
					                    </span>
										<div style="padding-top: 5px;font-size: 13px;color: rgb(60, 167, 109);">
											+{{parseFloat(Number(item.num)).toFixed(5).slice(0,-1) + ' Estate'}}
											<!--+{{parseFloat(Number(item.num)).toFixed(5).slice(0,-1) + ' USDT'}}-->
										</div>
									</van-col>
								</van-row>
							</div>
						</div>
					</van-list>
				</van-pull-refresh>
			</div>
		</div>
	</div>
</template>

<script>
	import { crowdfunding } from './../utils/api';
	import { formatDate } from './../utils/date';
	let _this;
	export default {
		name: "MySettlementRecord",
		data() {
			return {
				list: [],
				size: 10, // 每页数量
				current: 1,
				total: '', // 总数量
				listLength: '', //当前总数量
				isLoading: false,
				finished: false,
				loading: false,
			};
		},
		beforeCreate() {
			_this = this;
		},
		methods: {
			getList() {
				crowdfunding.getProjectDetailsMine({
					projectId: this.$route.query.projectId,
					type: 3,
					current: this.current,
					size: this.size
				}).then(res => {
					if(res.code == 200) {
						this.list = res.data.records;
						this.listLength = res.data.records.length;
						this.total = res.data.total;
						if(this.total > this.listLength) {
							this.size += 10;
							this.loading = false;
						} else {
							// 加载状态结束
							this.finished = true;
							this.loading = false;
						}
					}
				})
			},
			onRefresh() { // 下拉刷新
				this.getList();
				setTimeout(() => {
					this.$toast({
						duration: 800,
						message: _this.$t('MyDividend.v10')
					});
					this.isLoading = false;
				}, 500);
			},
			onLoad() { // 上拉加载
				this.getList();
			},
			onClickLeft() {
				this.$router.push({
					path: '/MyProject'
				});
			}
		},
		filters: {
			formatDate(time) {
				let date = new Date(time);
				return formatDate(date, 'yyyy-MM-dd hh:mm');
			}
		}
	}
</script>

<style lang="less" scoped>
	.overlay {
		background: rgb(245, 245, 245);
		color: black;
	}
	
	.head {
		background: white;
		color: black;
	}
	
	.head .return:after {
		border-color: #000;
	}
	
	.van-pull-refresh {
		overflow: visible!important;
	}
</style>